package dao.impl;

import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;


import dao.UsersDao;
import pojo.Teams;
import pojo.UserRoleProject;
import pojo.Users;
import util.DateTransfrom;

/** 
* @author WuYuan
* 
*/
public class UsersDaoImpl implements UsersDao {
	private SqlSessionTemplate sqlSessionTemplate;
	
	
	public SqlSessionTemplate getSqlSessionTemplate() {
		return sqlSessionTemplate;
	}

	public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
		this.sqlSessionTemplate = sqlSessionTemplate;
	}

	@Override
	public List<Users> findAllUsers() throws Exception {
		return sqlSessionTemplate.selectList("findAllUsers");
	}

	@Override
	public Users findUserByUsername(String username) throws Exception {
		return  (Users)sqlSessionTemplate.selectOne("findUserByUsername", username);
	}

	@Override
	public Users findUserByUser(Users u) throws Exception {
		// TODO Auto-generated method stub
		return  (Users)sqlSessionTemplate.selectOne("findUserByUser", u);
	}

	@Override
	public int addUser(Users u) throws Exception {
		System.out.println("创建用户的日期是"+DateTransfrom.transDateToStr(u.getCreateDate()));
		//Object [] objects =new Object[]{u.getUserName(),u.getPassword(),u.getEmail(),DateTransfrom.transDateToStr(u.getCreateDate()),u.getTel(),u.getHeadimage()};
		// TODO Auto-generated method stub
		return sqlSessionTemplate.insert("addUser",u);
	}

	@Override
	public Teams findTeamByUandT(String userid, String teamid) throws Exception {
		// TODO Auto-generated method stub
		Object [] objects =new Object[]{userid,teamid};
		return  (Teams)sqlSessionTemplate.selectOne("findTeamByUandT", objects);
	}

	@Override
	public UserRoleProject findUrpidByURP(String userid, String roleid, String projectid) throws Exception {
		// TODO Auto-generated method stub
		Object [] objects =new Object[]{userid,roleid,projectid};
		return  (UserRoleProject)sqlSessionTemplate.selectOne("findUrpidByURP", objects);
	}

}
